//用户收藏
function collect(user,collectId,type) {
    if(!user){
        $(document).dialog({
            type: "confirm",
            style: "IOS",
            titleShow: false,
            content: "亲，还没登录不能收藏哦！，",
            buttons: [{
                name: "马上登录",
                callback: function() {
                    location.href = "/login.html";
                }
            }]
        });
        return;
    }
    var usrId = user.id;
    //获取用户对该文章的收藏状态params.id
    $.get("/collects/users/get", {type: type, collectId: collectId,userId:usrId}, function (data) {
        if (!data) {//没有收藏，执行保存
            if(type==0){
                $("#collectBtn").removeClass("fa fa-star-o fa-1x");
                $("#collectBtn").addClass("fa fa-star fa-1x");
            }else if(type==1){
                $("#collectBtn").removeClass("fa fa-heart-o fa-1x");
                $("#collectBtn").addClass("fa fa-heart fa-1x");
            }

            $.post("/collects/users/save", {type: type, collectId: collectId,  userId: usrId}, function (data) {
                $("#collects").html(data);
                $(document).dialog({
                    type: 'notice',
                    infoText: '收藏成功',//提示
                    autoClose: 2500,//xx秒后自动消失
                    position: 'center'  // center: 居中; bottom: 底部
                });
            })
        }
        else {//有收藏，执行删除
            if(type==0){
                $("#collectBtn").removeClass("fa fa-star fa-1x");
                $("#collectBtn").addClass("fa fa-star-o fa-1x");
            }else if(type==1){
                $("#collectBtn").removeClass("fa fa-heart fa-1x");
                $("#collectBtn").addClass("fa fa-heart-o fa-1x");
            }

            $.post("/collects/users/delete", {type: type, collectId: collectId, userId: usrId}, function (data) {
                $("#collects").html(data);
                $(document).dialog({
                    type: 'notice',
                    infoText: '取消收藏成功',//提示
                    autoClose: 2500,//xx秒后自动消失
                    position: 'center'  // center: 居中; bottom: 底部
                });
            })
        }
    })

}


//用户点赞
function like(user,likeId,type) {
    if(!user){
        $(document).dialog({
            type: "confirm",
            style: "IOS",
            titleShow: false,
            content: "亲，还没登录不能点赞哦！，",
            buttons: [{
                name: "马上登录",
                callback: function() {
                    location.href = "/login.html";
                }
            }]
        });
        return;
    }
    var usrId = user.id;
    //获取用户对该文章的点赞状态params.id
    $.get("/likes/users/get", {type: type, likeId: likeId,userId:usrId}, function (data) {
        if (!data) {//没有点赞
            if(type==0){//游记
                $("#likeBtn").removeClass("fa fa-thumbs-o-up fa-1x");
                $("#likeBtn").addClass("fa fa-thumbs-up fa-1x");
            }else if(type==1){//攻略
                $("#likeBtn").removeClass("fa fa-thumbs-o-up fa-1x");
                $("#likeBtn").addClass("fa fa-thumbs-up fa-1x");
            }
            $.post("/likes/users/save", {type: type, likeId: likeId,  userId: usrId}, function (data) {
                $("#likes").html(data);
                // if(data.success){
                    $(document).dialog({
                        type: 'notice',
                        infoText: '点赞成功',//提示
                        autoClose: 2500,//xx秒后自动消失
                        position: 'center'  // center: 居中; bottom: 底部
                    });
                // }
            })
        }
        else {//有点赞
            if(type==0){
                $("#likeBtn").removeClass("fa fa-thumbs-up fa-1x");
                $("#likeBtn").addClass("fa fa-thumbs-o-up fa-1x");
            }else if(type==1){
                $("#likeBtn").removeClass("fa fa-thumbs-up fa-1x");
                $("#likeBtn").addClass("fa fa-thumbs-o-up fa-1x");
            }

            $.post("/likes/users/delete", {type: type, likeId: likeId, userId: usrId}, function (data) {
                $("#likes").html(data);
                    $(document).dialog({
                        type: 'notice',
                        infoText: '取消点赞成功',//提示
                        autoClose: 2500,//xx秒后自动消失
                        position: 'center'  // center: 居中; bottom: 底部
                    });
            })

        }
    })
}



